-
Notifications
You must be signed in to change notification settings - Fork 310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(wallet): only mark change address used if create_tx
succeeds
#1579
fix(wallet): only mark change address used if create_tx
succeeds
#1579
Conversation
699a6bb
to
b15c97c
Compare
This might also be related to #1577 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking this forward. Let me know what you think about the next_unused_spk_without_revealing
idea.
9341041
to
18ecd06
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 18ecd06
18ecd06
to
004b0ca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 004b0ca
It looks good! Thanks for addressing this issue.
I left some suggestions and nit below.
51fe144
to
849e136
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 849e136
If no drain script is specified in tx params then we get it from the change keychain by looking at the next unused address. We want to mark the change address used so that other callers won't attempt to use the same address between the time we create the tx and when it appears on chain. Before, we marked the index used regardless of whether a change output is finally added. Then if creating a PSBT failed, we never restored the unused status of the change address, so creating the next tx would have revealed an extra one. Now we only mark the change address used if we successfully create a PSBT and the drain script is used in the change output.
849e136
to
75989d8
Compare
Made last minute changes @notmandatory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 606fa08
If no drain script is specified in tx params then we get it from the change keychain by looking at the next unused address. Before this PR we marked the index used regardless of whether a change output is finally added. Then if creating a psbt failed, we never restored the unused status of the change address, so creating the next tx would have revealed an extra one.
We want to mark the change address used so that other callers won't attempt to use the same address between the time we create the tx and when it appears on chain. With this PR we only mark the change address used if we successfully create a psbt and the drain script is used in the change output.
fixes #1578
Notes to the reviewers
An early idea was to unmark the change address used if we fail to create a tx due to
InsufficientFunds
, but after looking into it I figure it doesn't totally make sense to mark the address used before we've determined that a change output is necessary. Further,create_tx
can fail in other ways besides running coin selection, so I moved themark_used
logic to the end of the function.Changelog notice
Fixed an issue that caused an unused internal address to be skipped when creating transactions (#1578)
Checklists
All Submissions:
cargo fmt
andcargo clippy
before committingBugfixes: